package com.igoal.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.compass.annotations.Searchable;

@Entity
@Table(name = "city")
@Searchable
public class City extends BaseObject implements Serializable, Audit {
	private static final long serialVersionUID = 6138114390614323311L;
	
	private Long id;
	private String cityName;
	private Date createDate;
	private Date updatedate;
	private DataStatus status;
	private UserInfo userInfo;
	
	@OneToOne(fetch = FetchType.LAZY)
	@PrimaryKeyJoinColumn
	public UserInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	public City() {
	}

	@Id
	@Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "city_name", nullable = false)
	public String getCityName() {
		return this.cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "cdate", nullable = false, length = 19)
	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date cdate) {
		this.createDate = cdate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "mdate", nullable = false, length = 19)
	public Date getUpdateDate() {
		return this.updatedate;
	}

	public void setUpdateDate(Date mdate) {
		this.updatedate = mdate;
	}

	@Enumerated(EnumType.STRING)
	@Column(name = "status", nullable = false)
	public DataStatus getStatus() {
		return this.status;
	}

	public void setStatus(DataStatus status) {
		this.status = status;
	}

	public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
 
        City that = (City) o;
 
        if (id != null ? !id.equals(that.getId()) : that.getId() != null) return false;
 
        return true;
    }
 
    public int hashCode() {
        return (getId() != null ? getId().hashCode() : 0);
    }


	@Override
	public String toString() {
		if(this.cityName != null){
			return cityName;
		}
		return null;
	}
}
